var LabelInfo = require('../models/label');

module.exports = {
  deleteLabel: function (req, res) {
    console.log("删除label信息:"+req.body)
    LabelInfo.delete(req.body.nodeID).then(function (result) {
      res.send({status: true})
    }, function (error) {
      res.send({status: 400, message: error})
    })
  },
  addLabel: function (req, res) {
    // var newStation = {name: req.body.name, nodeId: req.body.nodeId, type: req.body.type, nodeNum: req.body.nodeNum};
    LabelInfo.create(req.body).then(function (result) {
      res.send(result)
    }, function (error) {
      res.send({status: false, message: error})
    })
  },
  getAllLabelInfo: function (req, res) {
    LabelInfo.all().then(function (stations) {
      res.send(stations)
    }, function (error) {
      res.send({status: 400, message: error})
    })
  },
  updateLabel: function (req, res) {
    var data = {
      name: req.body.name,
      nodeID: req.body.id,
      nodeType: req.body.nodeType
    };
    console.log("------------更新信息")
    console.log(req.body)
    LabelInfo.update({nodeID: req.body.nodeID}, data,req.body.history).then(function (result) {
      res.send(result)
    }, function (error) {
      res.send({status: false, message: error})
    })
  }
};